package com.example.customviewtest.bilbil

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.customviewtest.R
import com.example.customviewtest.utils.toast
import kotlinx.android.synthetic.main.b_controlview_layout.view.*

/**
 * @auther XuDan on 2020/7/17.
 */
class ControlView @JvmOverloads constructor(
        context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr), View.OnClickListener {

    init {
        LayoutInflater.from(context).inflate(R.layout.b_controlview_layout, this, true)
        control_img_add.setOnClickListener(this)
        initRv(control_rv)
    }

    private fun initRv(controlRv: RecyclerView) {
        controlRv.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
    }

    override fun onClick(v: View?) {
        when (v) {
            control_img_add -> {
                toast(context, "添加图片")
            }
        }
    }
}